﻿Node = function(canvasName, x, y, width, height, isMovable)
{
    this.m_canvasName = canvasName;

    this.m_width = width;
    this.m_height = height;
    this.m_x = x;
    this.m_y = y;
    this.m_isMovable = isMovable;
    this.m_angle = 0;

    this.m_canvas;
    this.m_context;

    this.m_isTransformChanged = true;    
}

Node.prototype.init = function()
{
    this.m_canvas = document.getElementById(this.m_canvasName);
    this.m_context = this.m_canvas.getContext("2d");
    this.render();
}

Node.prototype.update = function(dt)
{
    if (this.m_isTransformChanged)
    {
        this.render();
        this.m_isTransformChanged = false;
    }
}

Node.prototype.moveTo = function(x, y)
{
    this.m_x = x;
    this.m_y = y;

    this.m_isTransformChanged = true;
}

Node.prototype.moveBy = function(x, y)
{
    this.m_x += x;
    this.m_y += y;

    this.m_isTransformChanged = true;
}

Node.prototype.collide = function(node)
{
}

Node.prototype.isMovable = function()
{
    return this.m_isMovable;
}

Node.prototype.doDraw = function(node)
{
}

Node.prototype.draw = function()
{
    this.doDraw(this);
}

Node.prototype.render = function()
{
    this.m_context.save();

    this.m_context.clearRect(0, 0, this.m_canvas.width, this.m_canvas.height);
    this.m_context.translate(this.m_x, this.m_y);
    this.m_context.rotate(this.m_angle * Math.PI / 180);
    this.draw();

    this.m_context.restore();    
}
